layui.use(['form','layer'], function(){
  $ = layui.jquery;
  var form = layui.form
  ,layer = layui.layer;



  function Prov(){
    $.get("{:URL('Common/area')}?id=0",function(data){
      alert(data);
      var cate = data;
      for (var i=0;i<cate.length;i++) 
      { 
        var option = '<option value="'+cate[i]['AreaId']+'">'+cate[i]['AreaName']+'</option>';
        $("#ProvId").append(option);
      }
      form.render('select');
    });

  }

  function City(id){
    $.get("{:URL('Common/area')}?id="+id,function(data){
      var cate = data;
      for (var i=0;i<cate.length;i++) 
      { 
        var option = '<option value="'+cate[i]['id']+'">'+cate[i]['name']+'</option>';
        $("#CityId").append(option);
      }
      form.render('select');
    });
  }

  function County(id){
    $.get("{:URL('Common/area')}?id="+id,function(data){
      var cate = data;
      for (var i=0;i<cate.length;i++) 
      { 
        var option = '<option value="'+cate[i]['id']+'">'+cate[i]['name']+'</option>';
        $("#CountyId").append(option);
      }
      form.render('select');
    });
  }

  $(document).ready(function(){
    $("#ProvId").empty();
    $("#ProvId").append('<option value="">请选择省</option>');
    $("#CityId").empty();
    $("#CityId").append('<option value="">请选择市</option>');
    $("#CountyId").empty();
    $("#CountyId").append('<option value="">请选择县/区</option>');
    Prov();
    form.on('select(ProvId)', function(data){
      $("#CityId").empty();
      $("#CityId").append('<option value="">请选择市</option>');
      $("#CountyId").empty();
      $("#CountyId").append('<option value="">请选择县/区</option>');
      if (data.value) {
        City(data.value);
      }
    });
    form.on('select(CityId)', function(data){
      $("#CountyId").empty();
      $("#CountyId").append('<option value="">请选择县/区</option>');
      if (data.value) {
        County(data.value);
      }
    });
  });
});